package cn.bytecollege.admin.controller;

import cn.bytecollege.admin.service.UserService;
import cn.bytecollege.common.constant.Resource;
import cn.bytecollege.common.entity.Page;
import cn.bytecollege.common.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UserListController",value = "/super/userList")
public class UserListController extends HttpServlet {
    private UserService userService = null;
    public UserListController(){userService = new UserService();}
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
    @Override
    protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String index = request.getParameter("index");
        int pageIndex = (index==null)?1:Integer.parseInt(index);
        String size = request.getParameter("size");
        int pageSize = (size==null)?10:Integer.parseInt(size);

        Page<User> page = userService.findUserByPage(pageIndex,pageSize);
        //跳转页面
        request.setAttribute("page",page);
        request.getRequestDispatcher("/super/html/device/userList.jsp").forward(request,response);
    }
}
